package com.ilock.service;

import java.util.List;

import com.ilock.bean.Ilockstate;
import com.ilock.bean.IlockstateDAO;

public class LockStateServiceImpl implements ILockStateService {
	private IlockstateDAO IlockstateDAO;
	
	public IlockstateDAO getIlockstateDAO() {
		return IlockstateDAO;
	}

	public void setIlockstateDAO(IlockstateDAO ilockstateDAO) {
		IlockstateDAO = ilockstateDAO;
	}

	@Override
	public Ilockstate getLockStateById(int lockId) {
		System.out.println("enter3");
		List templist = IlockstateDAO.findByIlockInfoNumber(lockId);
		System.out.println("enter4");
		// TODO Auto-generated method stub
		Ilockstate ilockstate = null;
		if(!templist.isEmpty()){
			ilockstate = (Ilockstate) templist.get(0);
			System.out.println("getLockStateById:lockID:"+ilockstate.getIlockInfoNumber());
			System.out.println(ilockstate.getState());
		}else{
			System.out.println("getLockStateById error with wrong lockId ");
		}
		return ilockstate;
	}

	@Override
	public boolean updateLockState(Ilockstate ilockstate) {
		// TODO Auto-generated method stub
		boolean state = true;
		try{
			System.out.println(ilockstate.getIlockStateNumber());
			System.out.println(ilockstate.getIlockInfoNumber());
			System.out.println(ilockstate.getLastTime());
			System.out.println(ilockstate.getState());
			IlockstateDAO.merge(ilockstate);
		}catch(Exception e){
			state = false;
			System.out.println(e.getStackTrace());
		}
		return state;
	}

	@Override
	public List getLostConnLockList() {
		// TODO Auto-generated method stub
		return IlockstateDAO.getLoseConnLockList();
	}

}
